'use strict';
module.exports = {
	/**
	 * XXXnameXXX
	 * @url admin/pages/kh/imgs/img 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid,
			url,
			name: original_name,
			size,
			provider,
			file_id,
			category_id,
			width,
			height,
			orientation,
			duration
		} = data;
		let res = {
			code: 0,
			msg: ""
		};
		// 业务逻辑开始-----------------------------------------------------------
		let type = "other";

		let suffix = url.substring(url.lastIndexOf(".") + 1).toLowerCase();
		if (["png", "jpg", "jpeg", "gif", "bmp", "svg", "webp"].indexOf(suffix) > -1) {
			type = "image";
		} 
		if (vk.pubfn.isNull(original_name)) original_name = url;
		let dataJson = {
			user_id: uid,
			sort: 0,
			status: 0,
			type,
			url,
			display_name: original_name,
			original_name,
			size,
			file_id,
			provider,
			width,
			height,
			orientation,
			duration
		};
		console.log("dataJson",dataJson);
		if (vk.pubfn.isNotNull(category_id)) {
			dataJson["category_id"] = category_id;
		}
		await vk.baseDao.add({
			dbName: "dymz_imgs",
			dataJson
		});



		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}